package com.junit;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.tutorial.util.HibernateUtil;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sjzl.dao.impl.DaoImpl;
import com.sjzl.entity.Post;
import com.sjzl.entity.User;

public class UserTest {
	@Test
	public void main(){
		ApplicationContext ac = new ClassPathXmlApplicationContext(
				new String[] { "applicationContext.xml" });
		DaoImpl dao = (DaoImpl) ac.getBean("daoImpl");
		
		/*User user = (User) dao.get(User.class, 1);
		user.setDateLastActived(new Date());
		dao.update(user);*/
		
		User user2 = (User) dao.get(User.class, 2);
		System.out.println(user2.getAccount());
		List<Post> posts = user2.getPosts();
		System.out.println(posts.size());
		
		/*Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		User user = (User) session.get(User.class, 2);
		System.out.println(user.getAccount());
		session.getTransaction().commit();*/
		
		/*SimpleDateFormat dateformat1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss E");
		String a1=dateformat1.format(new Date());
		System.out.println("时间2:"+a1);*/
		
		
		/*List<Board> boardList = user.getBoards();
		System.out.println(boardList.size());*/
		
		/*for(int i = 0;i<1000;i++){
			User user = new User();
			user.setAccount("hj"+i);
			user.setPassword(""+i);
			user.setDateCreated(new Date());
			dao.save(user);
		}*/
		
		/*List<User> uList = dao.list("from User where id = (select max(id) from User)");
		System.out.println(uList.size());
		System.out.println(uList.get(0).getAccount());*/
	}
}
